const mongoose = require("mongoose")
const crypto = require("crypto") //引用加密模块
const PetownersSchema = new mongoose.Schema({
    // 宠物主人数据模型
    phone: String,  //宠物主人电话
    name: String,  //宠物主人
    memberscard: [{
        cardid: String  //卡号
    }],
    headim: String,  //照片
    address: String,  //送货地址
    area: String,  //区域
    store: String,  //积分
    pet:[{ //宠主宠物
        name: String,  //宠物名字 
        pettype: String, //宠物类型
        species: String, //宠物种类
        color: String, //宠物颜色
        birth: Date,  //出生日期
        character: String  //性格
    }]
}, {
        versionKey: false,
        timestamps: {
            createdAt: 'createTime',
            updatedAt: 'updateTime'
        } //自动管理修改时间
    })
const petowners = mongoose.model("petowners", PetownersSchema);

async function add(){
    const count = await petowners.countDocuments();
    if(count===0){
        petowners.create({
            phone:"18283934313",
            name:"南瓜",
            headim:"",
            address:"和信派都",
            area:"武侯区",
            store:"0",
            memberscard:[{cardid:"188888"}],
            // pet:[{name:"小脑斧",type:"猫",species:"国产猫",color:"橘色",birth:"2019-5-6",character:"活泼可爱"}]
        })
    }
}
// add();
module.exports = petowners;